#include <stdio.h>

int a;
int b;

int xchg(int *a, int *b)
{
	int c;

	c = *a;
	*b = *a;
	*b = c;
}

int main()
{
	a = 0x666;
	b = 0x777;

	xchg(&a, &b);

	return 0;
}

#if 0

/*
 * intel
 */
0000000000001129 <xchg>:
    1129:	f3 0f 1e fa          	endbr64 
    112d:	55                   	push   %rbp
    112e:	48 89 e5             	mov    %rsp,%rbp
    1131:	48 89 7d e8          	mov    %rdi,-0x18(%rbp)	// (rbp-0x18)=rdi
    1135:	48 89 75 e0          	mov    %rsi,-0x20(%rbp)	// (rbp-0x20)=rsi

    1139:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=(rbp-0x18) // pointer
    113d:	8b 00                	mov    (%rax),%eax	// eax=(rax)	  // value
    113f:	89 45 fc             	mov    %eax,-0x4(%rbp)	// (rbp-0x4)=eax

    1142:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=(rbp-0x18)
    1146:	8b 10                	mov    (%rax),%edx	// edx=(rax)

    1148:	48 8b 45 e0          	mov    -0x20(%rbp),%rax	// rax=(rbp-0x20)
    114c:	89 10                	mov    %edx,(%rax)	// (rax)=edx	

    114e:	48 8b 45 e0          	mov    -0x20(%rbp),%rax	// rax=(rpb-0x20)
    1152:	8b 55 fc             	mov    -0x4(%rbp),%edx	// edx=(rbp-0x4)
    1155:	89 10                	mov    %edx,(%rax)	// (rax)=edx
    1157:	90                   	nop
    1158:	5d                   	pop    %rbp
    1159:	c3                   	retq   

000000000000115a <main>:
    115a:	f3 0f 1e fa          	endbr64 
    115e:	55                   	push   %rbp
    115f:	48 89 e5             	mov    %rsp,%rbp
    1162:	c7 05 ac 2e 00 00 66 	movl   $0x666,0x2eac(%rip)        # 4018 <a>  	rip+0x2eac=0x666
    1169:	06 00 00 
    116c:	c7 05 9e 2e 00 00 77 	movl   $0x777,0x2e9e(%rip)        # 4014 <b>	rip+0x2e9e=0x777
    1173:	07 00 00 
    1176:	48 8d 35 97 2e 00 00 	lea    0x2e97(%rip),%rsi        # 4014 <b>	// rsi=rip+0x2e97
    117d:	48 8d 3d 94 2e 00 00 	lea    0x2e94(%rip),%rdi        # 4018 <a>	// rdi=rip+0x2e94
    1184:	e8 a0 ff ff ff       	callq  1129 <xchg>
    1189:	b8 00 00 00 00       	mov    $0x0,%eax
    118e:	5d                   	pop    %rbp
    118f:	c3                   	retq   

/*
 * arm
 */
000000000040051c <xchg>:
  40051c:	d10083ff 	sub	sp, sp, #0x20
  400520:	f90007e0 	str	x0, [sp, #8]	// [sp+8]=x0
  400524:	f90003e1 	str	x1, [sp]	// [sp]=x1

  400528:	f94007e0 	ldr	x0, [sp, #8]	// x0=[sp+8]
  40052c:	b9400000 	ldr	w0, [x0]	// w0=[x0]
  400530:	b9001fe0 	str	w0, [sp, #28]	// [sp+28]=w0

  400534:	f94007e0 	ldr	x0, [sp, #8]	// x0=[sp+8]
  400538:	b9400001 	ldr	w1, [x0]	// w1=[x0]
  40053c:	f94003e0 	ldr	x0, [sp]	// x0=[sp]
  400540:	b9000001 	str	w1, [x0]	// [x0]=w1

  400544:	f94003e0 	ldr	x0, [sp]	// x0=[sp]
  400548:	b9401fe1 	ldr	w1, [sp, #28]	// w1=[sp+28]
  40054c:	b9000001 	str	w1, [x0]	// [x0]=w1
  400550:	d503201f 	nop
  400554:	910083ff 	add	sp, sp, #0x20
  400558:	d65f03c0 	ret

000000000040055c <main>:
  40055c:	a9bf7bfd 	stp	x29, x30, [sp, #-16]!
  400560:	910003fd 	mov	x29, sp
  400564:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400568:	9100c000 	add	x0, x0, #0x30	// x0=411030
  40056c:	5280ccc1 	mov	w1, #0x666                 	// #1638
  400570:	b9000001 	str	w1, [x0]	[411030]=0x666
  400574:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400578:	9100b000 	add	x0, x0, #0x2c	// x0=41102c
  40057c:	5280eee1 	mov	w1, #0x777                 	// #1911
  400580:	b9000001 	str	w1, [x0]	// [41102c]=0x777
  400584:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400588:	9100b001 	add	x1, x0, #0x2c	// x1=41102c
  40058c:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400590:	9100c000 	add	x0, x0, #0x30	// x0=411030
  400594:	97ffffe2 	bl	40051c <xchg>	// xchg(x0,x1)
  400598:	52800000 	mov	w0, #0x0                   	// #0
  40059c:	a8c17bfd 	ldp	x29, x30, [sp], #16
  4005a0:	d65f03c0 	ret
  4005a4:	00000000 	.inst	0x00000000 ; undefined

#endif
